// pages/weddingMan/team/scedules/scedules.js
import { getTeamScheduleInfo } from '../../../../api/weddingMan/team';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    showLoadMoreCurrent: false,
    loadMoreTextCurrent: '',
    scrollHeight: '0px',
    schedules: [],
    showCount: 10,
    currentPage: 1,
    totalPage: 1,
    teamId: null,
    date: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id) {
      const teamId = options.id

      this.setData({
        teamId
      })
    }
    const add0 = n => n > 9 ? n : '0' + n
    if (!this.date) {
      const today = new Date()
      const date = `${today.getFullYear()}-${add0(today.getMonth() + 1)}`
      this.setData({
        date
      })
    }	
    this.initTeamSchedules()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  initTeamSchedules() {

    this.setData({
      totalPage: 1,
      currentPage: 1,
      showCount: 10,
      schedules: []
    })
    this.getTeamScheduleInfo()
  },
  bindDateChange(e) {
    const {
      value
    } = e.detail
    
    const date = value
    this.setData({
      date
    })
    this.initTeamSchedules()
  },

  toHome(e) {
    const { id , isMutualFollow} = e.currentTarget.dataset
    const tmpGzStatus = isMutualFollow === '1' ? '2' : '1';
    wx.navigateTo({
      url: `/pages/weddingMan/personal/personal?id=${id}&gzStatus=${tmpGzStatus}`
    })
  },
  getTeamScheduleInfo() {

 

    const {
      currentPage,
      showCount,
      teamId: team_id,
      date,
    } = this.data
    if (!team_id) {
      return;
    }
    getTeamScheduleInfo({
        currentPage,
        showCount,
        team_id,
        date
      }).then(res => {
        
        const schedules = res.data.list||[]
        this.setData({
          schedules
        })
      })
      .catch(err => {
        
      })
  },

})